home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / ab20 / unarced / datacomm / ncomm / pbview.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  3KB  |  113 lines

  1. /* PbView for use with NComm V1.9 or later */
  2. /* Displays an NComm phonebook file in a  */
  3. /* very ugly and badly formatted way :-) */
  4. /* Public Domain by Torkel Lodberg 1991 */
  5.  
  6. #include <stdio.h>
  7. #include <exec/types.h>
  8. #include <exec/memory.h>
  9. #include <intuition/intuition.h>
  10. #include <proto/intuition.h>
  11. #include <proto/graphics.h>
  12. #include <proto/exec.h>
  13. #include <fcntl.h>
  14. #include <ctype.h>
  15. #include <math.h>
  16.  
  17. #define NEW_FILETYPE_PHONE  6
  18.  
  19. static struct pb_Data {        /*** V1.92-> file format ***/
  20.     UBYTE           name[41];
  21.     UBYTE           phone[61];
  22.     UBYTE           comment[41];
  23.     UBYTE           pass_word[30];
  24.     UBYTE           script_file[33];
  25.     UBYTE           config_file[33];
  26.     UBYTE           macro_file[33];
  27.     UBYTE           char_set;     /*** 0-12        ***/
  28.     UBYTE           baud;     /*** 0-11 (300 - 115200)    ***/
  29.     UBYTE           data_length; /*** 7 or 8        ***/
  30.     UBYTE           parity;     /*** None, odd, even    ***/
  31.     UBYTE           stop_bits;     /*** 1 - 2        ***/
  32.     UBYTE           duplex;     /*** Full - half    ***/
  33.     UBYTE           swap_del_bs; /*** Swap Del/BS       ***/
  34.     UBYTE           protocol;    /*** Protocol (0-6)    ***/
  35.     UBYTE           future[62];
  36. };
  37.  
  38. static int      fd = NULL;    /* File handle */
  39.  
  40. UBYTE           wb_open;    /* Started from workbench? */
  41.  
  42. void
  43. cleanup(text)            /* Exit program cleanly */
  44.     char           *text;
  45. {
  46.     if (text)
  47.     printf("%s\n", text);
  48.     if (fd > 0)
  49.     close(fd);
  50.     if (wb_open)
  51.     Delay(100);
  52.     exit(0);
  53. }
  54.  
  55. void
  56. brk()
  57. {                /* Called by every CTRL-C / D keypress */
  58.     printf("*** BREAK\n");
  59.     cleanup(NULL);
  60. }
  61.  
  62. void
  63. main(argc, argv)        /* Main program */
  64.     int             argc;
  65.     char           *argv[];
  66. {
  67.     char            ch, answer[256], infile[256];
  68.     struct pb_Data  data;
  69.  
  70.     if (!argc)
  71.     wb_open = TRUE;
  72.     else
  73.     wb_open = FALSE;
  74.  
  75.     if (onbreak(&brk))
  76.     cleanup(NULL);
  77.     chkabort();
  78.  
  79.     if (wb_open || argc > 2) {
  80.     printf("PbView for use with NComm V1.9 or later.\n"
  81.            "Public Domain by Torkel Lodberg 1991\n\n");
  82.     if (!wb_open) {
  83.         printf("   Usage: PbConvert [phonebook]\n\n");
  84.         cleanup(NULL);
  85.     }
  86.     }
  87.  
  88.     if (argc < 2)
  89.        strcpy(infile, "NComm:NComm.phone");
  90.     else
  91.        strcpy(infile, argv[1]);
  92.  
  93.     if (wb_open) {
  94.     printf("Enter name of phonebook file (Enter=NComm:NComm.phone): ");
  95.     gets(answer);
  96.     if (strlen(answer))
  97.         strcpy(infile, answer);
  98.         printf("\n");
  99.     }
  100.  
  101.     if ((fd = open(infile, O_RDONLY, NULL)) == -1 || read(fd, &ch, 1) != 1)
  102.        cleanup("Cannot open data-file");
  103.  
  104.     if (ch != NEW_FILETYPE_PHONE)
  105.     cleanup("Error reading NComm.phone: Illegal file type");
  106.  
  107.     while ((read(fd, (char *) &data, sizeof(struct pb_Data))) == sizeof(struct pb_Data)) {
  108.           printf("%-30s %s\n", data.name, data.phone);
  109.     }
  110.  
  111.     cleanup(NULL);
  112. }
  113.